home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / attall / attmain.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  8.3 KB  |  268 lines

  1. DefInt A-Z
  2. Global AllowFormToMove
  3. Global MStartX
  4. Global MStartY
  5. Global StartLeft
  6. Global StartTop
  7. Global Moved
  8. Global PosLeft
  9. Global PosTop
  10. Global Cancelling As Integer
  11. Global PlayOnceOnly As Integer
  12. Global SoundAborted As Integer
  13. Global Resizing As Integer
  14. Global AtomicTimeWasSet As Integer
  15.  
  16. Global Const PM_NOREMOVE = &H0
  17. Global Const WM_MENUSELECT = &H11F
  18. Global Const WM_COMMAND = &H111
  19. Declare Sub DirectedYield Lib "Kernel" (hTask As Integer)
  20.  
  21. 'Declares for Hotkey
  22. Declare Function GetAsyncKeyState Lib "User" (ByVal VKCODE%) As Integer
  23. Declare Function PeekMessage Lib "User" (lpMsg As MSG, ByVal hWnd As Integer, ByVal wMsgFilterMin As Integer, ByVal wMsgFilterMax As Integer, ByVal wRemoveMsg As Integer) As Integer
  24. Declare Function MessageReceived Lib "attsupp.dll" () As Long
  25. Declare Function TaskWindow Lib "attsupp.dll" (ByVal hTask As Integer) As Integer
  26. Declare Function PrinterStatus Lib "attsupp.dll" () As Integer
  27. Declare Function PrinterJobs Lib "attsupp.dll" () As Integer
  28. Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  29. Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  30. Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
  31. Declare Function GetTopWindow Lib "User" (ByVal hWnd As Integer) As Integer
  32. Declare Function IsWindowEnabled Lib "User" (ByVal hWnd As Integer) As Integer
  33. Declare Function IsWIndowVisible Lib "User" (ByVal hWnd As Integer) As Integer
  34. Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
  35. Declare Function SndPlaySOund Lib "MMsystem" (ByVal lpSound As String, ByVal Flags As Integer) As Integer
  36. Global Const SND_NOSTOP = &H10
  37. Global Const GWL_STYLE = (-16)
  38. Global Const WS_POPUP = &H80000000
  39. Global Const GW_HWNDFIRST = 0
  40. Global Const GW_HWNDNEXT = 2
  41. Global Const SW_RESTORE = 9
  42.  
  43. Global VK_Rotate1 As Integer
  44. Global VK_Rotate2 As Integer
  45. Global VK_Rotate3 As Integer
  46.  
  47. Global VK_Toggle1 As Integer
  48. Global VK_Toggle2 As Integer
  49. Global VK_Toggle3 As Integer
  50.  
  51. Global VK_Plus2 As Integer
  52. Global VK_Plus3 As Integer
  53. Global Const VK_SHIFT = &H10    'SHIFT key
  54. Global Const VK_CONTROL = &H11  'CTRL key
  55. Global Const VK_MENU = &H12 'ALT key
  56.  
  57. Global Const VK_R = &H52     'R key
  58. Global Const VK_T = &H54    'T key
  59. Declare Function GetModuleHandle% Lib "Kernel" (ByVal lpProgramName$)
  60. Declare Function GetModuleUsage% Lib "Kernel" (ByVal hProgram%)
  61. Declare Function GetActiveWindow Lib "User" () As Integer
  62. Declare Function SetFocusAPI Lib "user" Alias "SetFocus" (ByVal hWnd As Integer) As Integer
  63. Declare Function Ctl3dRegister Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer
  64. Declare Function Ctl3dAutoSubClass Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer
  65. Declare Function Ctl3dUnregister Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer
  66. Global Hw%
  67.  
  68.  
  69. Global Const LOGPIXELSX = 88    '  Logical pixels/inch in X
  70. Global Const LOGPIXELSY = 90    '  Logical pixels/inch in Y
  71. '---Default distance units, based on font space...
  72. Global gHStd As Integer
  73. Global gVStd As Integer
  74. '---Twips per pixel (horizontal & vertical)
  75. Global GTwpsPerPxlX As Integer
  76. Global GTwpsPerPxlY As Integer
  77. Global yDPI As Integer
  78. Global xDPI As Integer
  79.  
  80. '===============================
  81. '*** API Functions
  82. '===============================
  83. Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
  84.  
  85. Sub Main ()
  86. LastHour = -1
  87. LastJob = -1
  88. Hw% = GetModuleHandle("ATT.EXE")
  89. gmu% = GetModuleUsage(Hw%)
  90. If gmu% > 1 Then
  91.    'MsgBox ("Already running..." + Format$(gmu%))
  92.    AppActivate "AllTheTime"
  93.    End 'Program
  94. End If
  95.  
  96. Y% = Ctl3dRegister(Hw%)
  97. Y% = Ctl3dAutoSubClass(Hw%)
  98.  
  99.   '---Get display's horizontal dots per logical inch, set gTwpsPerPxlX
  100.   xDPI = GetDeviceCaps(AllTheTime.hDC, LOGPIXELSX)
  101.   GTwpsPerPxlX = 1440 / xDPI
  102.  
  103.   '---Get display's vertical dots per logical inch, set gTwpsPerPxlY
  104.   yDPI = GetDeviceCaps(AllTheTime.hDC, LOGPIXELSY)
  105.   GTwpsPerPxlY = 1440 / yDPI
  106.  
  107. Load Settings
  108. AllTheTime.Show
  109. WeHaveFocus = True
  110. SetStayOnTop (Settings.StayOnTop.Value)
  111. VK_Rotate1 = VK_CONTROL  'CTRL key
  112. VK_Rotate2 = VK_MENU     'ALT key
  113.  
  114. VK_Toggle1 = VK_CONTROL  'CTRL key
  115. VK_Toggle2 = VK_MENU     'ALT key
  116.  
  117. VK_Plus2 = VK_MENU     'ALT key
  118.  
  119. PlayOnceOnly% = True
  120. Call SetSize
  121. LastHour = -1
  122. Call SetTime
  123. PlayOnceOnly% = False
  124.  
  125. Do While DoEvents()
  126.   'Debug.Print PrinterStatus(), PrinterJobs()
  127.   'Debug.Print GetActiveWindow()
  128.   T& = MessageReceived()
  129.   'On Error Resume Next
  130.   TWind& = T& \ 65536
  131.   'If Err <> 0 Then MsgBox "Here 1"
  132.   'On Error Resume Next
  133.   TCommand& = T& Mod 65536
  134.   'If Err <> 0 Then MsgBox "Here 2"
  135.   'On Error GoTo 0
  136.   
  137.   If TWind& = AllTheTime.hWnd Then
  138.      If TCommand& = IDM_EXIT Then
  139.     TTT% = SndPlaySOund("", 0)  'hush!
  140.     If MsgBox("Exit All The Time?", 4) = 6 Then
  141.        DeleteMenus
  142.        End 'Program
  143.     End If
  144.      End If
  145.      If TCommand& = IDM_SETTINGS Then
  146.        DblCFlag% = True
  147.      End If
  148.      If TCommand& = IDM_ABOUT Then
  149.           Form3.Show 1
  150.      End If
  151.      If ((TCommand& - IDM_TASKS) > 0) And ((TCommand& - IDM_TASKS) <= TaskListItems) Then
  152.     On Error Resume Next
  153.     'AppActivate TaskList(TCommand& - IDM_TASKS).WTitle
  154.     Call SwitchToThisWindow(TaskList(TCommand& - IDM_TASKS).hWnd, 1)
  155.     On Error GoTo 0
  156.     'Debug.Print TCommand&, TaskWindow(TCommand&)
  157.     'DirectedYield (TCommand&)
  158.     'TW% = TaskWindow(TCommand&)
  159.     'TT% = GetWindowText(TW%, WName, 200)
  160.     'TT% = ShowWindow(TW%, SW_RESTORE)
  161.     '' Global Const SW_RESTORE = 9
  162.   
  163.     'TT% = SetFocusAPI(TW%)
  164.      End If
  165.   
  166.   End If
  167.   If WeHaveFocus Then
  168.     If GetActiveWindow() <> AllTheTime.hWnd Then
  169.       WeHaveFocus = False
  170.     End If
  171.   Else
  172.     If GetActiveWindow() = AllTheTime.hWnd Then
  173.       WeHaveFocus = True
  174.       If AllTheTime.Left >= Screen.Width - 15 Then
  175.      AllTheTime.Left = AllTheTime.Tag
  176.       End If
  177.     End If
  178.   End If
  179.  
  180.  
  181.   If DblCFlag% Then
  182.       DblCFlag% = False
  183.       Settings.WindowState = 0
  184.       On Error Resume Next
  185.       If Err <> 0 Then MsgBox "Here 3"
  186.       On Error Resume Next
  187.       Settings.Top = Screen.Height / 2 - (Settings.Height / 2)
  188.       If Err <> 0 Then MsgBox "Here 4"
  189.       On Error GoTo 0
  190.       Moved = False
  191.       SaveSettings
  192.       'Settings.Left = Screen.Width
  193.       Settings.Left = Screen.Width / 2 - (Settings.Width / 2)
  194.       Settings.Show
  195.       Settings.SetFocus
  196.   End If
  197.  
  198.   If (LastTime& <> Int(Timer)) And Not (BusyBusy) Then
  199.       BusyBusy = True
  200.       LastTime& = Int(Timer)
  201.       Call SetTime
  202.       If Not Moved Then
  203.      Call SetSize
  204.       End If
  205.       BusyBusy = False
  206.   End If
  207.  
  208.   'Most significant bit = key is down
  209.    vkr1% = GetAsyncKeyState(VK_Rotate1)
  210.    vkr1msb% = vkr1% And &H8000
  211.    vkr2% = GetAsyncKeyState(VK_Rotate2)
  212.    vkr2msb% = vkr2% And &H8000
  213.    vkr3% = GetAsyncKeyState(VK_Rotate3)
  214.    vkr3msb% = vkr3% And &H8000
  215.    vkt3% = GetAsyncKeyState(VK_Toggle3)
  216.    vkt3msb% = vkt3% And &H8000
  217.   
  218.    vkp2% = GetAsyncKeyState(VK_Plus2)
  219.    vkp2msb% = vkp2% And &H8000
  220.    vkp3% = GetAsyncKeyState(VK_Plus3)
  221.    vkp3msb% = vkp3% And &H8000
  222.    If (vkr1msb% = -32768) And (vkr2msb% = -32768) And (vkr3% <> 0) Then
  223.       'Beep
  224.       Do Until (GetAsyncKeyState(VK_Rotate3) And &H8000) = 0
  225.       Loop
  226.         If AllTheTime.Left >= Screen.Width - 15 Then
  227.            AllTheTime.Left = AllTheTime.Tag
  228.         End If
  229.   
  230.         For I% = 0 To 4
  231.         If Settings.Option3D1(I%).Value Then S% = I%
  232.         Next I%
  233.         Settings.Option3D1((S% + 1) Mod 5).Value = True
  234.         Settings.Option3D1(S%).Value = False
  235.         Call PositionATT
  236.    End If
  237.  
  238.    If (vkr1msb% = -32768) And (vkr2msb% = -32768) And (vkt3% <> 0) Then
  239.       Do Until (GetAsyncKeyState(VK_Toggle3)) >= 0
  240.       Loop
  241.   
  242.       If AllTheTime.Left >= Screen.Width - 15 Then
  243.      AllTheTime.Left = AllTheTime.Tag
  244.       Else
  245.      AllTheTime.Tag = AllTheTime.Left
  246.      AllTheTime.Left = Screen.Width - 15
  247.       End If
  248.    End If
  249.  
  250.    If (vkr2msb% = -32768) And (vkp3% <> 0) Then
  251.       Do Until (GetAsyncKeyState(VK_Plus3)) >= 0
  252.       Loop
  253.       Beep
  254.       AppActivate ("AllTheTime")
  255.       DoEvents
  256.       DoEvents
  257.       AllTheTime.SetFocus
  258.       DoEvents
  259.       DoEvents
  260.       'AllTheTime.Picture1.SetFocus
  261.       DoEvents
  262.       DoEvents
  263.       Call PictureMenuMouseDown(0, 0, 0, 0)
  264.    End If
  265.   Loop
  266. End Sub
  267.  
  268.